package com.mhc.suzuki.controller;

import com.mhc.suzuki.constant.ErrorCodeEnum;
import com.mhc.suzuki.service.LocationService;
import com.subaru.common.entity.BizResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by HW
 * on 2017/8/31 18:34.
 */
@Slf4j
@RestController
@RequestMapping(value = "/location")     // 通过这里配置使下面的映射都在/payment下，可去除
public class LocationController {


    @Autowired
    private LocationService locationService;

    /**
     * 根据手机号获取其归属地
     * @param mobilePhone
     * @return
     */
    @ApiOperation(value = "手机归属地查询", notes = "根据手机号获取其归属地")
    @ApiImplicitParam(name = "mobilePhone", value = "手机号", paramType = "path", required = true, dataType = "String")
    @RequestMapping(value = "/mobilePhone/{mobilePhone}", method = RequestMethod.GET)
    private BizResult<String> queryMobileLoaction(@PathVariable String mobilePhone){
        if(StringUtils.isBlank(mobilePhone)) {
            return BizResult.create(ErrorCodeEnum.PARAM_EMPTY.getErrCode(), ErrorCodeEnum.PARAM_EMPTY.getErrMsg());
        }

        String location = locationService.getLocation(mobilePhone);
        return BizResult.create(location, true, ErrorCodeEnum.SUCCESS.getErrCode(), ErrorCodeEnum.SUCCESS.getErrMsg());

    }

}
